package com.bao.shop.controller;

import com.bao.shop.entity.Cart;
import com.bao.shop.entity.Goods;
import com.bao.shop.entity.User;
import com.bao.shop.service.CartService;
import com.bao.shop.service.GoodsService;
import com.bao.shop.service.UserService;
import com.bao.shop.service.impl.CartServiceImpl;
import com.bao.shop.service.impl.GoodsServiceImpl;
import com.bao.shop.service.impl.UserServiceImpl;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author baoye
 * @date 2024-07-25/18:09
 */
public class SystemMessage {
    public static final UserService USER_SERVICE=new UserServiceImpl();
    public static final CartService CART_SERVICE=new CartServiceImpl();
    public static final GoodsService GOODS_SERVICE=new GoodsServiceImpl();

    public static final Scanner INPUT =UserService.INPUT;
    public static final ArrayList<User> USER_LIST=UserService.USER_LIST;
    public static void main(String[] args) {
        boolean loginFlag=false;
        User nowUser = null;
       while(true){
           System.out.println("********************电器商城********************\n");
           System.out.println("\t\t\t\t   1.用户注册");
           System.out.println("\t\t\t\t   2.用户登录");
           System.out.println("\t\t\t\t   3.退出系统\n");
           System.out.println("************************************************");
           System.out.print("请输入操作:");
           switch(INPUT.nextInt()){
               case 1:
                   USER_SERVICE.register(USER_SERVICE.registerManagement());
                   break;
               case 2:
                   nowUser= USER_SERVICE.login();
                   loginFlag=nowUser!=null;
                   break;
               default:
                   System.err.println("退出系统");
                   return;
           }
           while(loginFlag){
               System.out.println("********************电器商城********************\n");
               System.out.println("\t\t\t\t   1.选择商品");
               System.out.println("\t\t\t\t  2.我的购物车");
               System.out.println("\t\t\t\t   3.个人信息");
               System.out.println("\t\t\t\t    4. 注销\n");
               System.out.println("************************************************");
               System.out.print("请输入操作:");
               switch(INPUT.nextInt()){
                   case 1:
                       System.out.println("商品购买");
                       GOODS_SERVICE.buyGoods(nowUser);
                       break;
                   case 2:
                       System.out.println("购物车");
                       CART_SERVICE.pay(nowUser);
                       break;
                   case 3:
                       System.out.print("个人信息");
                       USER_SERVICE.printUser(nowUser);
                       break;
                   default:
                       loginFlag= USER_SERVICE.loginOut();
                       System.err.println("注销");
                       break;
               }
           }
       }

    }
}
